﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net.Core;
using log4net.Appender;
using Microsoft.Practices.Composite.Logging;

namespace WpfRcp.Logging.Log4Net
{
    public class LogManagerAppender : AppenderSkeleton
    {
        private readonly WpfRcp.Services.LogManager m_LogManager;

        public LogManagerAppender(WpfRcp.Services.LogManager logManager)
        {
            m_LogManager = logManager;
        }

        protected override void Append(LoggingEvent loggingEvent)
        {
            m_LogManager.AddEntry(new Log4NetLogEntry() { 
                Message = loggingEvent.RenderedMessage, 
                Level = loggingEvent.Level,
                Domain = loggingEvent.Domain,
                ThreadName = loggingEvent.ThreadName,
                TimeStamp = loggingEvent.TimeStamp
            });
        }

    }
}
